<?php

namespace App\Admin\Renderable;

use App\Admin\Repositories\WxSlideshow;
use App\Wen\Utils\FieldUtils;
use Dcat\Admin\Grid;
use Dcat\Admin\Grid\LazyRenderable;

class BannerRender extends LazyRenderable
{
    public function grid(): Grid
    {
        return Grid::make(new WxSlideshow(), function (Grid $grid) {
            global $__MINI_GLOBAL_TENANT_ID__;
            if($__MINI_GLOBAL_TENANT_ID__ > 0){
                $grid->model()->where('tenant_id', '=', $__MINI_GLOBAL_TENANT_ID__);
            }
            $grid->model()->orderBy('id','desc');
            $grid->column('id')->sortable();
            $grid->column('poster', '轮播图')->image('',80);
            $grid->column('sort', '排序')->editable();
            $grid->column('slideshow_type', '类型')->using(FieldUtils::getUrlTypes())->label([
                'default' => 'primary', // 设置默认颜色，不设置则默认为 default
            ]);
            $grid->column('target_id', '跳转id');
            $grid->column('slideshow_state', '状态')->switch();
//            $grid->column('created_at');
            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
            $grid->disableBatchActions();
            $grid->disableActions();
        });
    }
}
